package com.episode5;

import static com.util.HtmlStringUtil.getFooterHtml;
import static com.util.HtmlStringUtil.getHeaderHtml;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;


public class HeaderFilter implements Filter {

	@Override
	public void destroy() {
		// အသုံးပြုရန်မလိုအပ်ပါ
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse res,
			FilterChain chain) throws IOException, ServletException {
		PrintWriter writer = res.getWriter();
		writer.println(getHeaderHtml(req.getParameter("id"), req.getParameter("title")));
		chain.doFilter(req, res);
		writer.println(getFooterHtml());		
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// အသုံးပြုရန်မလိုအပ်ပါ
	}

}
